<template>
  <div class="mod-menu">
    <el-form ref="paramsRef" :inline="true" :model="params">
      <!-- v-if="isAuth('sys:balance:bill:list')" -->
      <el-form-item label="会员账号" prop="mobile">
        <el-input v-model="params.mobile" placeholder="会员手机号" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员昵称" prop="nickname">
        <el-input v-model="params.nickname" placeholder="会员昵称" clearable></el-input>
      </el-form-item>
<!--      <el-form-item label="会员身份" prop="grade">-->
<!--        <el-select v-model="params.grade" clearable placeholder="请选择会员身份">-->
<!--          <el-option v-for="(item, index) in provinceArr" :key="index" :label="item.label" :value="item.value"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="已付金额档次" prop="consumption_amount">-->
<!--        <el-select v-model="params.consumption_amount" clearable placeholder="请选择已付金额档次">-->
<!--          <el-option v-for="(item, index) in consumptionArr" :key="index" :label="item.label" :value="item.value"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="晋升为云掌柜的月份">-->
<!--        <el-date-picker-->
<!--          v-model="timer"-->
<!--          type="month"-->
<!--          placeholder="选择月份"-->
<!--          format="yyyy-MM"-->
<!--          value-format="yyyy-MM"-->
<!--          @change="handleTimer">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="success" @click="getDataList()">查询</el-button>
        <el-button type="warning" @click="resetparams()">重置</el-button>
        <el-button type="primary" @click="exportAll()">导出数据</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border @sort-change="changeTableSort" style=" width: 100%">
      <el-table-column prop="mobile" align="center" label="会员账号">
      </el-table-column>
      <el-table-column prop="nickname" align="center" label="会员昵称">
      </el-table-column>
<!--      <el-table-column prop="role_name" align="center" label="会员身份">-->
<!--        <template slot-scope="{ row }">-->
<!--          <div v-for="(v, i) in provinceArr" :key="i" v-if="v.value === row.grade">-->
<!--            {{ v.label }}-->
<!--            <span style="color:red" v-if="row.total_amount >= 30000">-->
<!--              <br/>(云掌柜)-->
<!--            </span>-->
<!--          </div>-->
<!--          &lt;!&ndash; {{ row.grade == 0 ? '普通会员' : '团长' }} &ndash;&gt;-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column prop="total_amount" sortable="custom" align="center" label="已付金额">
      </el-table-column>
      <el-table-column prop="team_grade" sortable="custom" align="center" label="团队等级">
        <template slot-scope="scope">
          <span>
            {{
              scope.row.team_grade === 1 ? 'V1' :
              scope.row.team_grade === 2 ? 'V2' :
              scope.row.team_grade === 3 ? 'V3' :
              scope.row.team_grade === 4 ? 'V4' :
              scope.row.team_grade === 5 ? 'V5' :
              scope.row.team_grade === 6 ? 'V6' :
              scope.row.team_grade === 7 ? 'V7' :
                  '无'
            }}
           </span>
        </template>
      </el-table-column>
      <el-table-column prop="director_grade" sortable="custom" align="center" label="董事等级">
        <template slot-scope="scope">
          <span>
            {{
              scope.row.director_grade === 8 ? '一星董事' :
              scope.row.director_grade === 9 ? '二星董事' :
              scope.row.director_grade === 10 ? '三星董事' :
                            '无'
            }}
           </span>
        </template>
      </el-table-column>
      <el-table-column prop="balance" sortable="custom" align="center" label="可用余额">
        <template slot-scope="scope">
          <el-button type="success" plain @click="checkBalance(scope.row.id)">{{
            scope.row.balance
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="commission_able" sortable="custom" align="center" label="贡献值">
        <template slot-scope="scoped">
          <div>
            {{ isToFixed(scoped.row.commission_able, 2) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="activating" align="center" label="激活状态">
        <template slot-scope="scope">
          <span>{{ scope.row.activating ? '激活' : '未激活' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="integral_able" sortable="custom" align="center" label="可用积分">
        <template slot-scope="scope">
          <el-button type="success" plain @click="checkIntegral(scope.row.id)">{{ isToFixed(scope.row.integral_able, 8) }}</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="commission_able" align="center" label="可用服务积分">
      </el-table-column> -->
      <el-table-column prop="lock_status" align="center" label="账户启用状态">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.lock_status" :active-value="0" :inactive-value="1" inactive-color="#B9B9B9" @change="changeSwitch(scope.row)" />
          <span>{{ scope.row.lock_status == 0 ? '正常' : '锁定' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="ofline_shopowner" align="center" label="是否为线下店长">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.ofline_shopowner" :active-value="1" :inactive-value="0" inactive-color="#B9B9B9" @change="changeOflineShopownerSwitch(scope.row)" />
          <span>{{ scope.row.ofline_shopowner == 0 ? '不是' : '是' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="create_time" sortable="custom" align="center" label="注册时间" width="155">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">查看</el-button>
          <el-button type="text" size="small" @click="changeReferences(scope.row.id)">修改推荐</el-button>
          <!-- <el-button type="text" size="small" @click="openSelIdentity(scope.row)">设置会员身份
          </el-button> -->
          <el-button type="text" size="small" @click="changeConsumption(scope.row)">修改贡献值
          </el-button>
          <!-- <el-button  type="text" size="small" @click="edit(scope.row.id)">重置密码  </el-button> -->
          <el-button type="text" size="small" @click="changeBalance(scope.row)">修改余额</el-button>
          <el-button type="text" size="small" @click="buyGoods(scope.row)">增加购买商品</el-button>
          <el-button type="text" size="small" @click="activation(scope.row.id)">激活</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="params.page" :page-sizes="[10, 20, 50, 100]" :page-size="params.limit" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    <!-- 查看详情 -->
    <user-details v-if="addOrUpdateVisible" ref="userDetails"></user-details>
    <!-- 查看金额 -->
    <money-detail v-if="moneyDetailVisible" ref="moneyDetail"></money-detail>
    <integral-detail v-if="integralVisible" ref="integralDetail"></integral-detail>
    <user-references v-if="changeState" ref="userReferences"></user-references>
    <!-- 编辑 -->
    <user-edit ref="userEdit"></user-edit>
    <!-- 设置会员身份 -->
    <el-dialog title="设置会员身份" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="form" :model="form" label-width="110px">
        <el-form-item label="会员身份" prop="service_system_province" :rules="rules.service_system_province">
          <el-select v-model="form.service_system_province" placeholder="请选择" @change="serviceChange" style="width: 100%">
            <el-option v-for="(item, index) in provinceArr" :key="item.value" :label="item.label" :value="index">
            </el-option>
          </el-select>
        </el-form-item>
        <div v-for="(v, i) in form.user_service_area_list" :key="i" v-if="
          form.service_system_province &&
          form.service_system_province !== 0 &&
          form.service_system_province !== 1
        ">
          <el-form-item label="所属省份" v-if="form.service_system_province != 1" :rules="rules.province_code" :prop="`user_service_area_list.${i}.province_code`">
            <div class="flex">
              <el-select v-model="v.province_code" placeholder="请选择" style="width: 100%" @change="provinceChange($event, i)">
                <el-option v-for="(item, index) in provinceList" :key="index" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <div class="addCls" v-if="form.service_system_province === 7">
                <i v-if="i == 0" @click="addProvince" type="primary" class="el-icon-circle-plus-outline"></i>
                <i v-if="i != 0" @click="delProvince(i)" type="primary" class="el-icon-remove-outline"></i>
              </div>
            </div>
          </el-form-item>
          <el-form-item label="所属市" v-if="
            form.service_system_province != 6 &&
            form.service_system_province != 7
          " :rules="rules.city_code" :prop="`user_service_area_list.${i}.city_code`">
            <el-select v-model="v.city_code" placeholder="请选择" style="width: 100%" @change="cityChange">
              <el-option v-for="(item, index) in cityList" :key="index" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属区" v-if="
            form.service_system_province != 5 &&
            form.service_system_province != 6 &&
            form.service_system_province != 7
          " :rules="rules.area_code" :prop="`user_service_area_list.${i}.area_code`">
            <el-select v-model="v.area_code" placeholder="请选择" style="width: 100%" @change="areaChange">
              <el-option v-for="(item, index) in areaList" :key="index" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item
            label="所属街道"
            v-if="
              form.service_system_province != 4 &&
                form.service_system_province != 5 &&
                form.service_system_province != 6 &&
                form.service_system_province != 7
            "
            :rules="rules.street_code"
            :prop="`user_service_area_list.${i}.street_code`"
          >
            <el-select
              v-model="v.street_code"
              placeholder="请选择"
              style="width: 100%"
              @change="streetChange"
            >
              <el-option
                v-for="(item, index) in streetList"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="所属社区"
            v-if="
              form.service_system_province != 3 &&
                form.service_system_province != 4 &&
                form.service_system_province != 5 &&
                form.service_system_province != 6 &&
                form.service_system_province != 7
            "
            :rules="rules.community_code"
            :prop="`user_service_area_list.${i}.community_code`"
          >
            <el-select
              v-model="v.community_code"
              placeholder="请选择"
              style="width: 100%"
              @change="communityChange"
            >
              <el-option
                v-for="(item, index) in communityList"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item> -->
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" :loading="btnLoading" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改贡献值 -->
    <el-dialog title="修改贡献值" :visible.sync="isConsumption" width="30%" :before-close="handleCloseConsumption">
      <el-form ref="consumptionFormRef" :model="consumptionForm" :rules="consumptionFormRules" label-width="100px">
        <el-form-item label="当前贡献值">
          <el-input v-model="consumptionForm.commission_able" disabled></el-input>
        </el-form-item>
        <el-form-item label="修改方式" prop="add">
          <el-radio v-model="consumptionForm.add" :label="true">增加</el-radio>
          <el-radio v-model="consumptionForm.add" :label="false">减少</el-radio>
        </el-form-item>
        <el-form-item label="变更额度" prop="value">
          <!-- <el-input
            v-model="consumptionForm.value"
            placeholder="请输入要变更的额度"
          ></el-input> -->
          <el-input-number :min="0" v-model="consumptionForm.value" :step="0.01" :precision="2"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="btnLoading" @click="submitConsumption">确 定</el-button>
        <el-button @click="handleCloseConsumption">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 修改余额弹窗 -->
    <el-dialog title="修改余额" :visible.sync="balanceDialog" width="30%">
      <el-form ref="balanceFormRef" :model="balanceForm" :rules="cbalanceFormRules" label-width="100px">
        <el-form-item label="当前余额">
          <el-input v-model="balanceForm.balance" disabled></el-input>
        </el-form-item>
        <el-form-item label="修改方式" prop="added">
          <el-radio v-model="balanceForm.added" :label="true">增加</el-radio>
          <el-radio v-model="balanceForm.added" :label="false">减少</el-radio>
        </el-form-item>
        <el-form-item label="变更额度" prop="value">
          <el-input-number :min="0" v-model="balanceForm.value" :step="0.01" :precision="2"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="btnLoading" @click="balanceSubmit">确 定</el-button>
        <el-button @click="closeBalanceDialog">取 消</el-button>
      </span>
    </el-dialog>
    <!--  购买商品赠送贡献值  -->
    <el-dialog title="购买商品赠送贡献值" :visible.sync="buyGoodsDialog" width="30%">
      <el-form ref="buyGoodsFormRef" :model="buyGoodsForm" :rules="buyGoodsFormRules" label-width="120px">
        <el-form-item label="当前贡献值余额">
          <el-input v-model="buyGoodsForm.commission_able" disabled></el-input>
        </el-form-item>
<!--        <el-form-item label="修改方式" prop="added">-->
<!--          <el-radio v-model="buyGoodsForm.added" :label="true">增加</el-radio>-->
<!--          <el-radio v-model="buyGoodsForm.added" :label="false">减少</el-radio>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="变更额度" prop="value">-->
<!--          <el-input-number :min="0" v-model="buyGoodsForm.value" :step="0.01" :precision="8"></el-input-number>-->
<!--        </el-form-item>-->
        <el-form-item label="请选择商品" prop="selectedInformation">
          <el-col :span="15">
            <el-select v-model="selectedInformation" placeholder="请选择商品" @change="handleChange">
              <el-option v-for="item in information" :key="item.id" :label="item.title" :value="item.id"></el-option>
            </el-select>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="btnLoading" @click="integralSubmit">确 定</el-button>
        <el-button @click="closebuyGoodsDialog">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Vue from 'vue'
import UserDetails from './user-details'
import MoneyDetail from './money-detail'
import UserEdit from './user-edit.vue'
import seviceApi from '@/api/serviceApi.js'
import integralDetail from './integral-detail'
import userReferences from './user-references.vue'
export default {
  data () {
    return {
      selectedInformation: '', // 用来存储选中的id
      selectedGoodsId: '',
      information: [],
      dataForm: {},
      params: {
        page: 1,
        limit: 10,
        mobile: '',
        nickname: '',
        sort_field: '',
        sort_type: 'ASC',
        grade: null,
        consumption_amount: null,
        shopkeeper_month: null
      },
      areaFeatureGoodsParams: {
        area_feature: 1,
        verify_status: 1,
      },
      timer: null,
      totalPage: 0,
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false,
      moneyDetailVisible: false,
      integralVisible: false,
      changeState: false,
      provinceArr: [
        { label: '激活会员', value: -1 },
        { label: '普通会员', value: 0 },
        { label: '团长', value: 1 }
        // { label: '爱心小屋', value: 2 },
        // { label: '服务驿站', value: 3 },
        // { label: '服务中心', value: 4 },
        // { label: '市级', value: 5 },
        // { label: '省级公司', value: 6 },
        // { label: '大区公司', value: 7 }
      ],
      consumptionArr: [
        { label: '', value: null },
        { label: '1 ~ 3万(不含3万)', value: 0 },
        { label: '3万以上(包含3万)', value: 1 },
      ],
      dialogVisible: false,
      form: {
        user_service_area_list: [{}]
      },
      provinceList: [], //省 列表
      cityList: [], //市 列表
      areaList: [], //区 列表
      streetList: [], //街道 列表
      communityList: [], //社区 列表
      rules: {
        service_system_province: [
          { required: true, message: '请选择会员身份', trigger: 'blur' }
        ],
        province_code: [
          { required: true, message: '请选择城市', trigger: 'blur' }
        ],
        city_code: [{ required: true, message: '请选择城市', trigger: 'blur' }],
        area_code: [{ required: true, message: '请选择区域', trigger: 'blur' }],
        street_code: [
          { required: true, message: '请选择街道', trigger: 'blur' }
        ],
        community_code: [
          { required: true, message: '请选择社区', trigger: 'blur' }
        ]
      },
      btnLoading: false,
      isConsumption: false,
      consumptionForm: {},
      consumptionFormRules: {
        add: {
          required: true,
          message: '修改方式选项不能为空',
          trigger: 'blur'
        },
        value: {
          required: true,
          message: '变更的额度不能为空',
          trigger: 'blur'
        }
      },
      balanceDialog: false,//修改余额弹窗
      balanceForm: {},//修改余额表单对象
      cbalanceFormRules: {
        added: {
          required: true,
          message: '请选择修改方式',
          trigger: 'blur'
        },
        value: {
          required: true,
          message: '变更的额度不能为空',
          trigger: 'blur'
        }
      },//修改余额表单验证
      buyGoodsDialog: false,
      buyGoodsForm: {
        user_obj_id: null,
        commission_able: null,
        added: true,
        value: null,
        goods_id: null,
      },
      buyGoodsFormRules: {
        added: {
          required: true,
          message: '请选择修改方式',
          trigger: 'blur'
        },
        value: [
          {
            required: true,
            message: '变更的额度不能为空',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  components: {
    UserDetails,
    UserEdit,
    MoneyDetail,
    integralDetail,
    userReferences
  },
  mounted () {
    this.getList()
    this.getAreaList()
    this.getAreaFeatureGoodsList()
  },
  methods: {
    handleChange (id) {
      // 在这里可以获取到当前选中的id，您可以在这里进行相应的逻辑处理
      this.form.informationId = id
    },
    handleTimer(e) {
      if (e) {
        this.params.shopkeeper_month = e
      } else {
        this.params.shopkeeper_month = null
      }
      console.log("e",e)
      console.log("timer",this.timer)
      console.log(this.params)
    },
    activation(id) {
      seviceApi.activationUser(id).then(res => {
        if (res && res.data.result) {
          alert('激活成功！')
          // window.location.reload()
        }else{
          alert('激活失败！')
        }
      })
    },
    getList () {
      seviceApi.getAccountList(this.params).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    getAreaFeatureGoodsList () {
      seviceApi.getAreaFeatureGoods().then(res => {
        if (res && res.data.code == 200) {
          this.information = res.data.page
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    changeTableSort (e) {
      if (e.order == 'descending') {
        this.params.sort_type = 'DESC'
      } else if (e.order == 'ascending') {
        this.params.sort_type = 'ASC'
      }
      this.params.sort_field = e.prop
      this.getDataList()
    },
    addProvince () {
      this.form.user_service_area_list.push({})
    },
    delProvince (index) {
      this.form.user_service_area_list.splice(index, 1)
    },
    handleClose () {
      this.form = {
        user_service_area_list: [{}]
      }
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
      this.dialogVisible = false
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.btnLoading = true
          seviceApi.updateServiceSystem(this.form).then(res => {
            this.btnLoading = false
            if (res && res.data.code == 200) {
              this.$message.success('设置成功！')
              this.getList()
              this.handleClose()
            }
          })
        }
      })
    },
    serviceChange () {
      this.form.user_service_area_list = [{}]
    },
    //获取省市区、街道、社区
    getAreaList (parentCode = 100000, columnIndex = 0) {
      seviceApi.streetList(parentCode).then(res => {
        if (res && res.data.code == 200) {
          if (columnIndex === 0) {
            this.provinceList = res.data.list
          } else if (columnIndex === 1) {
            this.cityList = res.data.list
          } else if (columnIndex === 2) {
            this.areaList = res.data.list
          } else if (columnIndex === 3) {
            this.streetList = res.data.list
          } else if (columnIndex === 4) {
            this.communityList = res.data.list
          }
          if (columnIndex <= 3) {
            this.communityList = []
            this.form.user_service_area_list[0].community_code = ''
            this.form.user_service_area_list[0].community_name = ''
          }
          if (columnIndex <= 2) {
            this.streetList = []
            this.form.user_service_area_list[0].street_code = ''
            this.form.user_service_area_list[0].street_name = ''
          }
          if (columnIndex <= 1) {
            this.areaList = []
            this.form.user_service_area_list[0].area_code = ''
            this.form.user_service_area_list[0].area_name = ''
          }
          if (columnIndex <= 0) {
            this.cityList = []
            this.form.user_service_area_list[0].city_code = ''
            this.form.user_service_area_list[0].city_name = ''
          }
        }
      })
    },
    // 选择省
    provinceChange (e, i) {
      let arr = this.provinceList
      let num = 0
      this.form.user_service_area_list.forEach(v => {
        if (v.province_code == e) {
          num++
          if (num >= 2) {
            this.$nextTick(() => {
              this.form.user_service_area_list[i].province_code = ''
            })
            this.$message.warning('此省市已被选择！')
            return
          }
        }
      })

      this.form.user_service_area_list[i].province_code = e
      for (let j = 0; j < arr.length; j++) {
        if (arr[j].value == e) {
          this.form.user_service_area_list[i].province_name = arr[j].label
          break
        }
      }
      this.form.user_service_area_list[0].city_code = ''
      this.form.user_service_area_list[0].city_name = ''
      this.$forceUpdate()
      this.getAreaList(e, 1)
    },
    // 选择 市
    cityChange (e) {
      let arr = this.cityList
      this.form.user_service_area_list[0].city_code = e
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].value == e) {
          this.form.user_service_area_list[0].city_name = arr[i].label
          break
        }
      }
      this.getAreaList(e, 2)
      this.$forceUpdate()
    },
    // 选择 区
    areaChange (e) {
      let arr = this.areaList
      this.form.user_service_area_list[0].area_code = e
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].value == e) {
          this.form.user_service_area_list[0].area_name = arr[i].label
          break
        }
      }
      this.getAreaList(e, 3)
      this.$forceUpdate()
    },
    // 选择 街道
    streetChange (e) {
      let arr = this.streetList
      this.form.user_service_area_list[0].street_code = e
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].value == e) {
          this.form.user_service_area_list[0].street_name = arr[i].label
          break
        }
      }
      this.getAreaList(e, 4)
      this.$forceUpdate()
    },
    // 选择 社区
    communityChange (e) {
      let arr = this.communityList
      this.form.user_service_area_list[0].community_code = e
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].value == e) {
          this.form.user_service_area_list[0].community_name = arr[i].label
          break
        }
      }
      this.$forceUpdate()
    },
    openSelIdentity (item) {
      this.form.user_id = item.id
      this.dialogVisible = true
    },
    changeConsumption (item) {
      this.consumptionForm.user_id = item.id
      this.consumptionForm.commission_able = item.commission_able
      this.isConsumption = true
    },
    submitConsumption () {
      this.$refs.consumptionFormRef.validate(valid => {
        if (valid) {
          seviceApi.editAccountConsumption(this.consumptionForm).then(res => {
            if (res && res.data.code == 200) {
              this.isConsumption = false
              this.consumptionForm = {}
              this.getList()
              this.$message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              })
            }
          })
        } else {
          this.$message.error('请完善表单')
        }
      })
    },
    handleCloseConsumption () {
      this.consumptionForm = {}
      this.isConsumption = false
    },
    // 点击修改余额  （开启 修改余额弹窗）
    changeBalance (row) {
      this.balanceForm.user_obj_id = row.id
      this.balanceForm.balance = row.balance;
      this.balanceDialog = true;
    },
    // 关闭 修改余额弹窗
    closeBalanceDialog () {
      this.balanceForm = {};
      this.$refs.balanceFormRef.resetFields()
      this.balanceDialog = false
    },
    balanceSubmit () {
      this.$refs.balanceFormRef.validate(valid => {
        if (valid) {
          seviceApi.adjustBalance(this.balanceForm).then(res => {
            if (res && res.data.code == 200) {
              this.closeBalanceDialog()
              this.getList()
              this.$message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              })
            }
          })
        } else {
          this.$message.error('请完善表单')
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.params.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.params.page = val
      this.getList()
    },
    // 查询
    getDataList () {
      this.params.page = 1
      this.getList()
    },
    resetparams () {
      this.params.sort_field = ''
      this.params.sort_type = 'ASC'
      this.params.shopkeeper_month = undefined
      this.$refs.paramsRef.resetFields()
      this.getDataList()
    },
    // updateStatus
    changeSwitch (row) {
      var param = {
        id: row.id,
        lock_status: row.lock_status,
      }
      seviceApi.updateStatus(param).then(res => {
        if (res && res.data.code == 200) {
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          })
        }
      })
    },
    changeOflineShopownerSwitch (row) {
      var param = {
        id: row.id,
        ofline_shopowner: row.ofline_shopowner
      }
      seviceApi.updateOflineShopownerStatus(param).then(res => {
        if (res && res.data.code == 200) {
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          })
        }
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.userDetails.init(id)
      })
    },
    // 查看详情
    edit (id) {
      this.$nextTick(() => {
        this.$refs.userEdit.init(id)
      })
    },
    changeReferences (id) {
      this.changeState = true
      this.$nextTick(() => {
        this.$refs.userReferences.init(id)
      })
      // console.log(id)
    },
    // 查看余额
    checkBalance (id) {
      this.moneyDetailVisible = true
      this.$nextTick(() => {
        this.$refs.moneyDetail.init(id)
      })
    },
    checkIntegral (id) {
      this.integralVisible = true
      this.$nextTick(() => {
        this.$refs.integralDetail.init(id)
      })
    },
    // 导出数据
    exportAll () {
      this.$confirm(`确定进行导出操作吗?`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let token = Vue.cookie.get('token')
          console.clear()
          console.log(this.params.grade)
          debugger
          window.location.href = `${this.$config.SERVER_URL}/admin/account/export?mobile=${this.params.mobile}&nickname=${this.params.nickname}&grade=${this.params.grade}&token=${token}&consumption_amount=${this.params.consumption_amount}&shopkeeper_month=${this.params.shopkeeper_month}`
        })
        .catch(() => { })
    },
    buyGoods (row) {
      this.buyGoodsForm.user_obj_id = row.id
      this.buyGoodsForm.commission_able = row.commission_able;
      this.buyGoodsForm.added = false
      this.buyGoodsDialog = true
    },
    integralSubmit () {
          this.buyGoodsForm.goods_id = this.selectedInformation;
          seviceApi.buyAreaGoods(this.buyGoodsForm).then(res => {
            if (res && res.data.code === 200) {
              this.closebuyGoodsDialog()
              this.getList()
              this.$message({
                showClose: true,
                message: '添加成功',
                type: 'success'
              })
            }
          })
    },
    closebuyGoodsDialog () {
      this.buyGoodsForm = {
        user_obj_id: null,
        integral_able: null,
        added: true,
        value: null
      }
      this.$refs.buyGoodsFormRef.resetFields()
      this.buyGoodsDialog = false
    }
  }
}
</script>
<style lang="scss">
.addCls {
  font-size: 24px;
  color: #17b3a3;
  margin-left: 20px;
  cursor: pointer;
}

.el-icon-remove-outline {
  color: rgb(255, 0, 0);
}
</style>
